/*
	author www
	date 2012-04-12
*/

var placeholder = {
	init:function ($obj){
		var $input = null;
		if($obj&&$obj.length>0){
			$input = $obj;
		} else {
			$input = $(".placeholder");
		}
		if(!$input||$input.length==0) return false;
		$input.bind('focus keydown',function(){
			var $this = $(this);
			if($this.data('hasPlaceholder')){
				placeholder.clearPlaceholder($this);
			}		
		});
		
		$input.bind('blur',function(){
			var $this = $(this);
			var placeValue = $this.attr("placeholder");
			if($this.val()==''){
				placeholder.showPlaceholder($this,placeValue);
			}		
		});
		if($input.length>0){
			$input.each(function(){
				var $this = $(this);
				var placeValue = $this.attr("placeholder");
				if($this.val() == ''||getBrowserV().ie=='6.0'){
					placeholder.showPlaceholder($this,placeValue);
				}		
			});
		}
	},
	clearPlaceholder:function(_this){
		_this.val("").removeClass("placeholder").data('hasPlaceholder',false);
	},
	showPlaceholder:function(_this,placeValue){
		_this.val(placeValue).addClass("placeholder").data('hasPlaceholder',true);	
	}
};
$(function (){
	placeholder.init();
});